/*
 *英才会硕信息科技有限公司拥有本软件的版权，拥有本软件版权2025   并保留所有权利。
 *Copyright 2021,YCHS Information&Science Technology Co.,Ltd,
 *All rights reserved.
 */
package com.ychs.lawyerback01.controller;


import com.ychs.lawyerback01.annotation.RequirePermission;
import com.ychs.lawyerback01.common.R;
import com.ychs.lawyerback01.common.ResultCode;
import com.ychs.lawyerback01.dto.RoleOptDTO;
import com.ychs.lawyerback01.dto.RoleQueryDTO;
import com.ychs.lawyerback01.service.RoleService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * @author xuehongjin
 * @version 1.0
 * @date 2025/8/22
 */
@RestController
@RequestMapping("/api/role")
public class RoleController {

    @Autowired
    private RoleService roleService;
    @RequirePermission("system:role:query")
    @PostMapping("/list")
    public R<?> getRolesByCondition(@RequestBody RoleQueryDTO roleQueryDTO) {
        return R.success(roleService.getRolesByCondition(roleQueryDTO));
    }
    @RequirePermission("system:role:add")
    @PostMapping("/add")
    public R<?> addRole(@Valid @RequestBody RoleOptDTO roleOptDTO) {
        int result = roleService.addRole(roleOptDTO);
        return result > 0 ? R.success("添加成功") : R.fail(ResultCode.ADD_FAILE);
    }
    @RequirePermission("system:role:update")
    @PutMapping("/edit")
    public R<?> editRole(@Valid @RequestBody RoleOptDTO roleOptDTO) {
        int result = roleService.editRole(roleOptDTO);
        return result > 0 ? R.success("修改成功") : R.fail(ResultCode.UPDATE_FAILE);
    }
    @RequirePermission("system:role:delete")
    @DeleteMapping("/delete")
    public R<?> deleteRoles(@RequestBody List<Long> roleIds) {
        int result = roleService.deleteRoles(roleIds);
        return result > 0 ? R.success("删除成功") : R.fail(ResultCode.DELETE_FAILE);
    }
}